import request from "@/util/request";
import type { LoginFrom, SysUser, captchaResponseData ,SysUserAuthRole,SysUserInfoVOResponseData, SysUserQuery } from "./type";
import type {PageType} from "@/api/type";

enum API {
    LOGIN_URL = "/auth/admin/login",
    LOGOUT_URL = "/auth/admin/logout",
    CAPECHA_URL = "/auth/captcha",
    SYS_USER_INFO_URL = "/system/user/info",
    SYS_USER_LIST_URL = "/system/user/list",
    SYS_USER_PAGE_URL = "/system/user/page",
    SYS_USER_BASE_URL = "/system/user",
    SYS_USER_ROLE_AUTH_URL = "/system/user/role/auth",
}

/**
 * 登录请求
 * @param data 表单数据
 */
export function reqLogin(data: LoginFrom) {
    return request<string>({
        url: API.LOGIN_URL,
        method: "post",
        data,
    });
}
/**
 * 退出登录
 * @returns
 */
export function reqLogout() {
    return request<string>({
        url: API.LOGOUT_URL,
        method: "post",
    });
}
/**
 *获取图形验证码
 * @export
 * @return {*}
 */
export function reqCaptcha() {
    return request<captchaResponseData>({
        url: API.CAPECHA_URL,
        method: "get",
    });
}

/**
 * 获取用户的详细信息vo
 * @returns vo
 */
export function reqGetSysUserInfoVO() {
    return request<SysUserInfoVOResponseData>({
        url: API.SYS_USER_INFO_URL,
        method: "get",
    });
}
/**
 * 创建用户接口
 * @param data 用户实体
 * @returns
 */
export function reqAddSysUser(data: SysUser) {
    return request<string>({
        url: API.SYS_USER_BASE_URL,
        method: "post",
        data,
    });
}
/**
 * 修改用户接口
 * @param data
 * @returns
 */
export function reqModifySysUser(data: SysUser) {
    return request<string>({
        url: API.SYS_USER_BASE_URL,
        method: "put",
        data,
    });
}
/**
 * 删除用户接口
 * @param userId
 * @returns
 */
export function reqDeleteSysUserById(userId: string | number) {
    return request<string>({
        url: API.SYS_USER_BASE_URL + "/" + userId,
        method: "delete",
    });
}

/**
 * 获取用户列表
 * @returns
 */
export function reqGetSysUserPage(sysUseQuery: SysUserQuery) {
    return request<PageType<SysUser>>({
        url: API.SYS_USER_PAGE_URL,
        method: "get",
        params: sysUseQuery,
    });
}

export function reqSysUserAuth(data: SysUserAuthRole) {
    return request<string>({
        url: API.SYS_USER_ROLE_AUTH_URL,
        method: "post",
        data,
    });
}
